import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import * as API from "@api/index";
import { HttpService } from '@core/http/http.service';

import { ToolsService } from '@shared/service/tools/tools.service';
import { BehaviorSubject } from 'rxjs';
import {SeoService} from "@core/seo/seo.service";
import {VideoRespVO} from "@interface/index";



@Injectable()
export class VideoService {
  public currentCategory: string;
  public _video: BehaviorSubject<VideoRespVO> = new BehaviorSubject<VideoRespVO>(null);
  public dataStore = {
    video: null
  };

  constructor(
    public httpService: HttpService,
    public toolsService: ToolsService,
    private _seoService: SeoService
  ) {
  }
  getSlider() {
    const url = API.AD_LIST_URL + '?adsType=banner&showPosition=44&rows=5';
    return this.httpService.get(url).map((res: Response) => res.json());
  };

  getCateList() {
    const url = API.VIDEO_CATE_URL;
    return this.httpService.get(url)
      .map((res: Response) => res.json());
  };
  /**
   * 获取单个视频信息
   * @param videoId 视频id
   */
  getDeVideoDetail(videoId: number | string) {
    const url = API.VIDEO_DETAIL + `?videoId=${videoId}`;
    this.toolsService.showLoading();
    this.httpService.get(url).map((res: Response) => res.json()).subscribe((res) => {
      this.toolsService.hideLoading();
      this.dataStore.video = res.data;
      this._video.next(this.dataStore.video);
      this._seoService.setTKD(
        `${res.data.videoName}_体育视频`,
        `${res.data.videoName}_视频,运动视频,体育视频,赛事视频`,
        `求苗体育视频频道全面展示了NBA视频，CBA视频，国际足球视频，英超视频，意甲视频，德甲视频，
        综合体育视频等体育比赛视频，并提供了体育花边和赛后赛事等`
      );
    });
  };
  get video() {
    return this._video.asObservable();
  }
  /**
   * 获取视频详情页面视频推荐列表
   * @param cataId 类别id
   */
  getVideoRecommendList(cataId: number, page: number = 1, rows: number = 10) {
    const url = API.VIDEO_RECOMMEND_LIST + `?cateId=${cataId}&page=${page}&rows=${rows}`;
    return this.httpService.get(url)
      .map((res: Response) => res.json());
  };
  /**
   * 获取相应类别视频信息
   * @param cateId 类别id
   */
  getCategory(cateId, page: number = 1, rows: number = 10) {
    const url = API.VIDEO_HOME_MORE + `?cateId=${cateId}&page=${page}&rows=${rows}`;
    return this.httpService.get(url)
      .map((res: Response) => res.json());
  };
}
